{include file="header.html"}
<div id="main">
  {include file="menus.html"}
  <div id="rightCon" class="clearfix layui-body">
    <div class="scroller">
      <div class="search-form clearfix">
        <form method="get" id="formSearch">
          <div class="webkit-box box-align-center">
            <input type="hidden" name="r" value="deposit/index" />
            <select class="querySelect" name="field">
              {html_options options=$search_options selected=$smarty.get.field}
            </select>
            <input class="infoTableInput mr10" type="text" name="search_name" value="{$smarty.get.search_name}" />
            {$lang.pay_status}
            <select class="querySelect" name="pay_status">
              <option value="">{$lang.no_limit}</option>
              {html_options options=$pay_status_list selected=$smarty.get.pay_status}
            </select>
            {$lang.money_from}
            <input class="queryInput2" type="text" value="{$smarty.get.money_from}" name="money_from" />
            {$lang.to}
            <input class="queryInput2" type="text" value="{$smarty.get.money_to}" name="money_to" class="pick_date" />
          </div>
          <div class="webkit-box box-align-center mt20">
            {$lang.add_time_from}
            <input class="queryInput" type="text" value="{$smarty.get.add_time_from}" id="add_time_from"
              name="add_time_from" class="pick_date" />
            {$lang.to}
            <input class="queryInput" type="text" value="{$smarty.get.add_time_to}" id="add_time_to" name="add_time_to"
              class="pick_date" />

            <input type="submit" class="layui-btn layui-bg-blue layui-btn-sm block width7"
              value="{$lang.query}" />
            <!--{if $filtered}-->
            <a class="layui-btn layui-btn-primary layui-btn-sm box-align-center"
              href="{url route='deposit/index'}">{$lang.cancel_query}</a>
            <!--{/if}-->
          </div>
        </form>
      </div>
      <div class="tablegrid">
        <table class="layui-hide" id="tablegrid" lay-filter="tablegrid"></table>
      </div>
      {include file="version.html"}
    </div>
  </div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
    <button class="layui-btn layui-bg-blue" lay-event="monthbill"><i class="layui-icon layui-icon-file-b"></i>月账单</button>
	  <button class="layui-btn layui-btn-primary layui-border-blue" lay-event="batdel"><i class="layui-icon layui-icon-close"></i>批量删除</button>
		<button class="layui-btn layui-btn-primary layui-border-black" lay-event="export"><i class="layui-icon layui-icon-export"></i>导出数据</button>
	</div>
</script>

<script type="text/html" id="colBar">
	  <a class="ml5 mr5 blue pointer" lay-event="edit">编辑</a>
  	<a class="ml5 mr5 blue pointer" lay-event="del" confirm="删除后将不能恢复，确认删除该项吗？">删除</a>
    <a class="ml5 mr5 blue pointer" lay-event="recharge" confirm="删除后将不能恢复，确认删除该项吗？">充值</a>
</script>

<script>
  layui.use('table', function () {
    var table = layui.table;

    table.render({
      elem: '#tablegrid'
      //,skin: 'line'
      , url: url(['deposit/index', $("#formSearch").serializeJson()])
      , toolbar: '#toolbar'
      , defaultToolbar: ['filter', /*'exports',*/ 'print']
      , title: '资金账户列表'
      //, size: 'lg'
      , cols: [[
        { type: 'checkbox', fixed: 'left' }
        , { field: 'account_id', title: 'ID', width: 70, fixed: 'left', unresize: true, sort: true }
        , { field: 'account', title: '账户', width: 200, sort: true, }
        , { field: 'username', title: '用户名', width: 230, sort: true }
        , { field: 'money', title: '金额', width: 160, sort: true }
        , { field: 'frozen', title: '冻结', width: 110, sort: true }
        , {
          field: 'pay_status', title: '开启余额支付', width: 160, sort: true, align: 'center', templet: function (res) {
            return res.pay_status == 'OFF' ? '<em class="no" ectype="inline_edit" controller="deposit" fieldname="pay_status" fieldid="' + res.account_id + '" fieldvalue="0" title="' + lang.editable + '"><i class="fa fa-ban"></i>' + lang.no + '</em>' : '<em class="yes" ectype="inline_edit" controller="deposit" fieldname="pay_status" fieldid="' + res.account_id + '" fieldvalue="1" title="' + lang.editable + '"><i class="fa fa-check-circle"></i>' + lang.yes + '</em>';
          }
        }
        , { field: 'add_time', title: '生成时间', width: 180, sort: true, align: 'center' }
        , { fixed: 'right', title: '操作', toolbar: '#colBar', width: 200, align: 'center' }
      ]]
      , page: {
        theme: 'blue'
      }
    });

    //监听头工具栏事件
    table.on('toolbar(tablegrid)', function (obj) {
      var checkStatus = table.checkStatus(obj.config.id);
      if (checkStatus.data.length <= 0) {
        return false;
      }
      var items = new Array();
      $.each(checkStatus.data, function (i, item) {
        items.push(item.account_id);
      });
      if (obj.event === 'batdel') {
        var btnObj = $('[lay-event="' + obj.event + '"]');
        btnObj.attr('confirm', '删除后将不能恢复，确认删除这 ' + items.length + ' 项吗？');
        ajaxRequest(btnObj, url(['deposit/delete', { id: items.join(',') }]), function () {
          table.reload('tablegrid');
        });
      } else if (obj.event === 'monthbill') {
        if (items.length > 1) {
          return layer.alert("只能选择一个用户查看月账单");
        }
        window.location.href = url(['deposit/monthbill', { userid: checkStatus.data[0].userid }]);

      } else if (obj.event === 'export') {
        window.location.href = url(['deposit/export', $.extend($("#formSearch").serializeJson(), { id: items.join(','), model: 'account' })]);
      }
    });

    //监听行工具事件
    table.on('tool(tablegrid)', function (obj) {
      var data = obj.data;
      if (obj.event === 'del') {
        var btnObj = $(obj.tr).find('[lay-event="' + obj.event + '"]');
        ajaxRequest(btnObj, url(['deposit/delete', { id: data.account_id }]), function () {
          obj.del();
        });
      } else if (obj.event === 'edit') {
        window.location.href = url(['deposit/edit', { id: data.account_id }]);
      } else if (obj.event === 'recharge') {
        window.location.href = url(['deposit/recharge', { id: data.account_id }]);
      }
    });
  });

  $(function () {
    $('#add_time_from').datepicker({ dateFormat: 'yy-mm-dd' });
    $('#add_time_to').datepicker({ dateFormat: 'yy-mm-dd' });
  });
</script>
{include file="footer.html"}